#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
using namespace std;
vector <int> smurf(vector <int> arr){
for(int i = 0; i < arr.size(); i++){
int k = 0;
for(int j = 0; j < arr.size() - 1; j++){
if(arr[j] > arr[j + 1]){
  int t = arr[j+1];
  arr[j+1] = arr[j];
  arr[j] = t;
  k++;
}
}

if(k == 0){
  break;
}
}
  return arr;
  
}
vector <int> papa_smurf(vector <int> arr1){
for(int i = 0; i < arr1.size(); i++){
int k = 0;
for(int j = 0; j < arr1.size() - 1; j++){
if(arr1[j] > arr1[j + 1]){
  int t = arr1[j+1];
  arr1[j+1] = arr1[j];
  arr1[j] = t;
  k++;
}
}

if(k == 0){
  break;
}
}
  return arr1;

}
vector <int> smurfetta(vector <int> arr2){
for(int i = 0; i < arr2.size(); i++){
int k = 0;
for(int j = 0; j < arr2.size() - 1; j++){
if(arr2[j] > arr2[j + 1]){
  int t = arr2[j+1];
  arr2[j+1] = arr2[j];
  arr2[j] = t;
  k++;
}
}

if(k == 0){
  break;
}
}
  return arr2;

}
int main(){
ifstream f1;
ifstream f2;
ifstream f3;
f1.open("m1_sorted.txt");
f2.open("m2_reverse.txt");
f3.open("m3_shuffle.txt");
vector <int> arr;
  vector <int> arr1;
  vector <int> arr2;
int x;
while (f1 >> x){
  arr.push_back(x);
}
while (f2 >> x){
  arr1.push_back(x);
}
while (f3 >> x){
  arr2.push_back(x);
}
double start_time = clock();
arr = smurf(arr);
double finish_time = clock();
cout << "m1_sorted " << (finish_time - start_time) / 1000 << " milliseconds\n";
  double start_time1 = clock();
  arr = papa_smurf(arr1);
  double finish_time1 = clock();
  cout << "m2_reverse " << (finish_time1 - start_time1) / 1000 << " milliseconds\n";
  double start_time2 = clock();
  arr = smurfetta(arr2);
  double finish_time2 = clock();
  cout << "m3_shuffle " << (finish_time2 - start_time2) / 1000 << " milliseconds";
}